<?php


testMyExceptionInstance();

function testExceptionInstance(){
	$exceptionInstance=new ExceptionInstance();
	//print_r($exceptionInstance);
	$exceptionInstance->catchException();
}

function testMyExceptionInstance(){
	$myexceptionInstance=new MyExceptionInstance();
	$myexceptionInstance->catchMyException();
}

/**
 * 
 * Exception类的用法
 * @author Administrator
 *
 */
class ExceptionInstance{
	/**
	 * 
	 * 抛出异常
	 * @throws Exception
	 */
	public function throwException(){
		//echo "测试php异常<br/>";
		throw new Exception("发生异常！",23);
		echo "ss";
	}
	
	/**
	 * 
	 * 捕获异常
	 */
	public function catchException(){
		try{
			$this->throwException();
		}catch(Exception $e){
			//print_r($e);
			echo "异常信息：".$e->getMessage()."<br/>";    
			echo "异常code：".$e->getCode()."<br/>";    
			echo "异常文件路径：".$e->getFile()."<br/>";    
			echo "异常行号：".$e->getLine()."<br/>";    
			
		}
	}
	
	public function test(){
		echo "测试";
	}
}

/**
 * 
 * MyException类的用法
 * @author Administrator
 *
 */
class MyExceptionInstance{
	/**
	 * 
	 * 抛出异常
	 * @throws MyException
	 */
	function throwMyException(){
		//echo "测试php异常<br/>";
		throw  new MyException("自定义异常", 21);
	
	}
	/**
	 * 
	 * 捕获异常
	 */
	function catchMyException(){
		try{
			$this->throwMyException();
		}catch(MyException $e){
			//print_r($e);
			echo "异常信息：".$e->getMessage()."<br/>";    
			echo "异常code：".$e->getCode()."<br/>";    
			echo "异常文件路径：".$e->getFile()."<br/>";    
			echo "异常行号：".$e->getLine()."<br/>";  
			echo "自定义：".$e->getErrorMsg()."<br/>";    
			
		}
	}
}





/**
 * 
 * 自定义异常
 * @author Administrator
 *
 */
class MyException extends Exception{
	public function getErrorMsg(){
		return "测试";
	}
}






?>